﻿CREATE VIEW [dbo].[ASMS_V_CapitalChangedRecord]
	AS 
SELECT CCR.*,
	S.Name as CreatorName,
case CCR.CapitalRoleType
	when 1 then (select C.[Name] from ASMS_Customer as C where C.Id = CCR.CapitalRole)
    when 2 then (select S.[Name] from ASMS_Supplier as S where S.Id = CCR.CapitalRole)
    when 3 then (select STAFF.[Name] from ASMS_Staff as STAFF where STAFF.Id = CCR.CapitalRole)
	else CCR.CapitalRole 
	end as CapitalRoleName
FROM [ASMS_CapitalChangedRecord] as CCR
	left join ASMS_Staff as S ON S.Id = CCR.Creator